#include"stdio.h"
#include"davinci-emac.h"

#define N_AREAS 3
static unsigned int base_address[N_AREAS]=
{
	EMAC_MDIO_BASE_ADDR,
	EMAC_WRAPPER_BASE_ADDR,
	EMAC_WRAPPER_RAM_ADDR

};
static unsigned int area_size[N_AREAS]=
{
	EMAC_MDIO_REG_SIZE,
	EMAC_WRAPPER_REG_SIZE,
	EMAC_WRAPPER_RAM_SIZE

};
void log(char *,...);
void davinci_emac_handler(
	  void *lpContext,
	  int op, 
	  unsigned int dwAddress,   // start dwAddress on 32bit bus
	  char *pszBuff,           // optional 
	  unsigned int nBytes )    // in or out buffer
{
	int n_area=*(char *)(lpContext);
	int offset;


	 if(n_area<3
		 &&(offset=dwAddress-base_address[n_area])<area_size[n_area])
	 {
 		 if(op==ADDR_RANGE_WRITE)
		 log("ETH%d: w %x %x\n",n_area,dwAddress,offset);
		 switch(op)
		 {
		 case ADDR_RANGE_READ:  


			 for(int i=0;i<nBytes;i++)
			 {

				 pszBuff[i]=0;//reg[n_area].b[i+offset];
				 //if(pszBuff[i]<' ')
					// printf("\\0x%02x",(unsigned char)pszBuff[i]);
				 //else
					// printf("%c",pszBuff[i]);
			 }
			 break;
		 case ADDR_RANGE_WRITE: 


			 //for(int i=0;i<nBytes;i++)
			 //{


			 //}
		
			 break;
		 default:
			 return;

	 }
	 }

}